package com.dayouzi.crawler_monitor.controller;

import com.dayouzi.crawler_monitor.base.result.R;
import com.dayouzi.crawler_monitor.pojo.entity.Crawler;
import com.dayouzi.crawler_monitor.pojo.page.PageBean;
import com.dayouzi.crawler_monitor.pojo.query.CrawlerListQuery;
import com.dayouzi.crawler_monitor.pojo.vo.AnalysisListVO;
import com.dayouzi.crawler_monitor.pojo.vo.CrawlerListVO;
import com.dayouzi.crawler_monitor.pojo.vo.OptionDataVO;
import com.dayouzi.crawler_monitor.service.AnalysisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@Api(description = "数据分析")
@RestController
@RequestMapping("/crawler/analysis")
@Slf4j
public class AnalysisController {
    
    @Autowired
    private AnalysisService analysisService;


    @ApiOperation("获取爬虫详情")
    @GetMapping("/getCrawlerDetail")
    public R getCrawlerDetail(
            @ApiParam(value = "爬虫id", required = true) Integer id
    ) {
        Crawler result = analysisService.getCrawlerDetail(id);
        return R.ok().data("result", result);
    }
    
    @ApiOperation("获取七日数据量")
    @GetMapping("/getOptionBySevenDay")
    public R getOptionBySevenDay(
            @ApiParam(value = "爬虫id", required = false) Integer id,
            @ApiParam(value = "聚合日期", required = true) @RequestParam String date
    ) {
        // 别问为啥要用hashMap这么不规范的返回方式，因为快寄了，没心思做了，凑合着看吧 --2023-11-01
        HashMap<String, int[]> result = analysisService.getOptionBySevenDay(id, date);
        return R.ok().data("result", result);
    }
    
    @ApiOperation("获取24小时数据量")
    @GetMapping("/getOptionBy24Hour")
    public R getOptionBy24Hour(
            @ApiParam(value = "爬虫id", required = false) Integer id,
            @ApiParam(value = "聚合日期", required = true) @RequestParam String date 
    ) {
        HashMap<String, int[]> result = analysisService.getOptionBy24Hour(id, date);
        return R.ok().data("result", result);
    }

    @ApiOperation("分页查询爬虫信息list")
    @PostMapping("/listPage/{page}/{limit}")
    public R listPage(
            @ApiParam(value = "当前页码", required = true) @PathVariable Integer page,
            @ApiParam(value = "每页记录数", required = true) @PathVariable Integer limit,
            @ApiParam(value = "查询对象", required = true) @RequestBody CrawlerListQuery crawlerListQuery
    ) {
        PageBean<AnalysisListVO> result = analysisService.listPage(page, limit, crawlerListQuery);
        return R.ok().data("result", result);
    }
    
    @ApiOperation("获取统计类名的饼图数据")
    @GetMapping("/getOptionByPieClass")
    public R getOptionByPie(
            @ApiParam(value = "爬虫id", required = false) Integer id,
            @ApiParam(value = "聚合日期", required = true) @RequestParam String date
    ) {
        List<HashMap<String, Integer>> result = analysisService.getOptionByPieClass(id, date);
        return R.ok().data("result", result);
    }

    @ApiOperation("获取统计处理状态的饼图数据")
    @GetMapping("/getOptionByPieStatus")
    public R getOptionByPieStatus(
            @ApiParam(value = "爬虫id", required = false) Integer id,
            @ApiParam(value = "聚合日期", required = true) @RequestParam String date
    ) {
        List<HashMap<String, Integer>> result = analysisService.getOptionByPieStatus(id, date);
        return R.ok().data("result", result);
    }
    
    
    
}
